{% load i18n admin_urls %}
<div class="submit-row">
  <el-button type="button" icon="el-icon-arrow-left" @click="prev()" size="small" style="float: left;margin-right: 10px;margin-bottom: 10px;">
    <span v-text="getTranslate('Go back')"></span>
  </el-button>
  {% if show_delete_link %}
    {% url opts|admin_urlname:'delete' original.pk|admin_urlquote as delete_url %}
    <el-button icon="el-icon-delete" type="danger" @click="del('{% add_preserved_filters delete_url %}')" size="small" style="float: left">
      {% trans "Delete" %}
    </el-button>
  {% endif %}
  {% if show_save_as_new %}
    <el-button type="primary" @click="formSubmit('_saveasnew','{% trans 'Save as new' %}',$event)" size="small">
      {% trans 'Save as new' %}
    </el-button>
  {% endif %}
  {% if show_save_and_add_another %}
    <input type="submit" class="el-button el-button--primary el-button--small" value="{% trans 'Save and add another' %}" name="_addanother">
  {% endif %}
  {% if show_save_and_continue %}
    <input type="submit" class="el-button el-button--primary el-button--small" value="{% trans 'Save and continue editing' %}" name="_continue">
  {% endif %}
  {% if show_save %}
    <input type="submit" class="el-button el-button--primary el-button--small" value="{% trans 'Save' %}" name="_save">
  {% endif %}
  <input type="hidden" name="actionName" value="actionValue" id="actionName">
</div>
<script type="text/javascript">
  new Vue({
    el: '.submit-row',
    data: {},
    methods: {
      del: function (url) {
        window.location.href = url;
      },
      formSubmit: function (name, v, e) {
        $("#actionName").attr('name', name).val(v);
        $("form").submit();
      },
      prev: function () {
        const array = location.pathname.split('/');
        if (array.length === 5 || array.length === 6) {
          window.location.href = '/' + array[1] + '/' + array[2];
        } else {
          const referrer = document.referrer;
          if (referrer && document.URL !== referrer) {
            window.location.href = referrer;
          } else {
            window.history.go(-1);
          }
        }
      }
    }
  })
</script>